package com.net;


import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;

/**
 * 原生app
 * @author DingQingbo
 *
 */
public class UrlConnectionD {
	public static void main(String[] args) throws URISyntaxException,
			IOException {
		URL url = new URL("http://www.baidu.com");
		HttpURLConnection  conn = (HttpURLConnection) url.openConnection();
		conn.setRequestMethod("GET");
        conn.setDoOutput(true);  
        conn.setInstanceFollowRedirects(true);  
        conn.setRequestProperty("content-type", "text/html");  
        conn.connect();//  
		
        InputStream is = conn.getInputStream();//拿到输入流  
        InputStreamReader reader=new InputStreamReader(is,"utf-8");  
        String jsonStr="";  
        int r=0;  
        while((r=reader.read())!=-1){  
        jsonStr+=(char)r;  
        }
        System.out.println(jsonStr);
        is.close();  
	}

}
